<?php

namespace App\Http\Controllers;


use Illuminate\Http\Request;
use Illuminate\Support\Facades\DB;

class LiuYanController extends Controller
{
    public function lists()
    {
        return view('liuyan.lists');
    }
    public function doLists(Request $request)
    {
        $key = $request->input('key', '');
        $pageSize = $request->input('limit', '10');
        $where = [];
        if (!empty($key)) {
            $where[] = ['username', 'like', '%' . $key . '%'];
        }
        //查询账号
        $count = DB::table('leaving')->where($where)->count();
        $goods = (array)DB::table('leaving')->where($where)->paginate($pageSize)->items();
        return $this->success($goods, '', ['count' => $count]);

    }


    public function del(Request $request)
    {
        try {
            $ids = $request->input('ids', '0');
            if (empty($ids)) throw new \Exception("删除失败");
            if (!is_array($ids)) {
                $ids = [$ids];
            }
            $res = DB::table('leaving')->whereIn('id', $ids)->delete();
        } catch (\Exception $e) {
            return $this->error($e->getMessage());
        }
        return $this->success();
    }


}
